#include "manano_common.h"

#include "mdtx-online/indicator/indicator_type_ordered.h"
namespace indi = mdtx::online::indicator;

using minmax = unary2<indi::minmax>;
using argminmax = unary2<indi::argminmax>;
using rollmin = unary1<indi::rollmin>;
using rollmax = unary1<indi::rollmax>;
using rollargmin = unary1<indi::rollargmin>;
using rollargmax = unary1<indi::rollargmax>;
using rollrank = unary1<indi::rollrank>;

using rollmedian = unary1<indi::rollmedian>;
using rollmedian_w = binary1<indi::rollmedian_w>;
using rollmedian_cu = unary1<indi::rollmedian_cu>;
using rollkth = unary1<indi::rollkth>;

void bind_indi_ordered(py::module &m)
{
    auto mod = m.def_submodule("order", "Rolling ordered indicators");
    {
        auto v = py::class_<minmax>(mod, "minmax")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &minmax::run, py::arg("x"), "Run calc")
                     .def("run", &minmax::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling min / max
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<argminmax>(mod, "argminmax")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &argminmax::run, py::arg("x"), "Run calc")
                     .def("run", &argminmax::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling argmin / argmax
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<rollmin>(mod, "min")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &rollmin::run, py::arg("x"), "Run calc")
                     .def("run", &rollmin::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling min
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<rollmax>(mod, "max")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &rollmax::run, py::arg("x"), "Run calc")
                     .def("run", &rollmax::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling max
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<rollargmin>(mod, "argmin")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &rollargmin::run, py::arg("x"), "Run calc")
                     .def("run", &rollargmin::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling argmin
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<rollargmax>(mod, "argmax")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &rollargmax::run, py::arg("x"), "Run calc")
                     .def("run", &rollargmax::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling argmax
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<rollrank>(mod, "rank")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &rollrank::run, py::arg("x"), "Run calc")
                     .def("run", &rollrank::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling rank
                    Args:
                        period (int) : rolling window period)mydoc";
    }

    {
        auto v = py::class_<rollmedian>(mod, "median")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &rollmedian::run, py::arg("x"), "Run calc")
                     .def("run", &rollmedian::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling median
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<rollmedian_w>(mod, "median_w")
                     .def(py::init<int>(), py::arg("period"))
                     .def("run", &rollmedian_w::run, py::arg("x"), py::arg("w"), "Run calc")
                     .def("run", &rollmedian_w::run2, py::arg("x"), py::arg("w"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling weighted median
                    Args:
                        period (int) : rolling window period)mydoc";
    }
    {
        auto v = py::class_<rollmedian_cu>(mod, "median_cu")
                     .def(py::init())
                     .def("run", &rollmedian_cu::run, py::arg("x"), "Run calc")
                     .def("run", &rollmedian_cu::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Cumulative median)mydoc";
    }

    {
        auto v = py::class_<rollkth>(mod, "kth")
                     .def(py::init<int, int>(), py::arg("period"), py::arg("k"))
                     .def("run", &rollkth::run, py::arg("x"), "Run calc")
                     .def("run", &rollkth::run2, py::arg("x"), "Run batch calc");
        v.doc() = R"mydoc(
                    Rolling kth element
                    Args:
                        period (int) : rolling window period
                        k (int) : kth element)mydoc";
    }
}
